package com.ash;

import JavaAPI.HttpsPostRequest;
import JavaAPI.Purchase;
import com.ash.service.TransactionService;

/**
 * Hello world!
 */
public class TestPurchase {


    public static void main(String[] args) {

        TransactionService transactionService = TransactionService.getInstance();

        HttpsPostRequest mpgReq = transactionService.getHttpsPostRequest();

        Purchase purchase = getPurchase();

        mpgReq.setTransaction(purchase);

        mpgReq.send();

        transactionService.printResult(mpgReq);
    }


    private static Purchase getPurchase() {
        java.util.Date createDate = new java.util.Date();
        String order_id = "Test" + createDate.getTime();
        String amount = "9.00";
        String pan = "5454545454545454";
        String expdate = "2501"; //YYMM format

        // 交易类别
        /**
         * 允许的值包括： 如果使用cof 这个值，需要根据cof payment indicator值进行决定
         *
         * 1 - 邮购/电话订单—单次交易
         * 2 - 邮购/电话订单—定期交易
         * 3 - 邮购/电话订单—分期付款
         * 4 - 邮购/电话订单—未知分类
         * 5 - 经过身份验证的电子商务交易 (VBV)
         * 6 - 未经身份验证的电子商务交易 (VBV)
         * 7 - 启用了SSL的商户
         */
        String crypt = "7";
        Purchase purchase = new Purchase();
        purchase.setOrderId(order_id);
        purchase.setAmount(amount);
        purchase.setPan(pan);
        purchase.setExpdate(expdate);
        purchase.setCryptType(crypt);
        purchase.setDynamicDescriptor("123456");

        // optional 建议都加
        purchase.setCustId("ootdbuy");

        return purchase;
    }
}
